//
//  HMTeacherSignInTwoCell.m
//  TEXTS
//
//  Created by 陈辉明 on 2017/12/5.
//  Copyright © 2017年 goldwin. All rights reserved.
//

#import "HMTeacherSignInTwoCell.h"
#import "HMTeacherAttendanceRecordModel.h"

#import "HNAudioView.h"
#import "HNAudioTapGestureRecognizer.h"

@interface HMTeacherSignInTwoCell()

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *picHeight;

@property (nonatomic, strong) HNAudioView *AudioView;



@end

@implementation HMTeacherSignInTwoCell

-(void)setModel:(HMTeacherAttendanceRecordModel *)model {
    _model = model;
    self.timeLabel.text = [NSString stringWithFormat:@"%@",model.createTime];
    if (model.pics.count == 0 ) {
        _picHeight.constant = 0;
        [self.onePic layoutIfNeeded];
        self.onePic.hidden = YES;
        self.twoPic.hidden = YES;
        self.onePic.image = nil;
        self.twoPic.image = nil;
    } else if (model.pics.count == 1) {
        _picHeight.constant = 50;
        self.onePic.hidden = NO;
        self.twoPic.hidden = YES;
        [self.onePic layoutIfNeeded];
        self.twoPic.image = nil;
        //图片浏览
        if (model.pics[0]) {
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.onePic sd_setImageWithURL:[NSURL URLWithString:model.pics[0]] placeholderImage:[UIImage imageNamed:@"icon_add_defaulttt"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                Tap.Img = self.onePic.image;
            }];
            [self.onePic addGestureRecognizer:Tap];
            self.onePic.userInteractionEnabled = YES;
        }
        

    } else {
        _picHeight.constant = 50;
        self.onePic.hidden = NO;
        self.twoPic.hidden = NO;
        [self.onePic layoutIfNeeded];
        if (model.pics[0]) {
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.onePic sd_setImageWithURL:[NSURL URLWithString:model.pics[0]] placeholderImage:[UIImage imageNamed:@"icon_add_defaulttt"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                Tap.Img = self.onePic.image;
            }];
            [self.onePic addGestureRecognizer:Tap];
            self.onePic.userInteractionEnabled = YES;
        }
        
        if (model.pics[1]) {
            HNAudioTapGestureRecognizer *Tap1 =[[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.twoPic sd_setImageWithURL:[NSURL URLWithString:model.pics[1]] placeholderImage:[UIImage imageNamed:@"icon_add_defaulttt"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                Tap1.Img = self.twoPic.image;
            }];
            [self.onePic addGestureRecognizer:Tap1];
            self.onePic.userInteractionEnabled = YES;
            
        }
    }
    
}

#pragma mark - 图片浏览

- (HNAudioView *)AudioView
{
    if (!_AudioView)
    {
        _AudioView = [[HNAudioView alloc] init];
    }
    return _AudioView;
}

#pragma mark - 图片全屏
/** 图片全屏手势 */
- (void)ImgAddTap:(HNAudioTapGestureRecognizer *)Tap
{
    [self ImgControllerWithImg:Tap.Img];
}
/** 图片全屏操作 */
- (void)ImgControllerWithImg:(UIImage *)Img
{
    [self.AudioView OpenWithImg:Img];
}



@end
